package org.dream.ui.chart;

import java.util.ArrayList;
import java.util.List;

import org.dream.domain.Daydeal;
import org.dream.util.PropUtil;

/**
 * 成交量线
 * 
 * @author qiuriyuchen E-mail:panpan_001@126.com
 */
public class PriceAveLine extends Polyline {
	public static int TURNOVERDAY;// 成交量均线时间
	static {
		TURNOVERDAY = PropUtil.getPropertyInteger("turnOverDay");
	}

	public PriceAveLine(List<Daydeal> daydealList, Chart chart, double minY, double maxY,int index) {
		super(chart,index);
		List<Double> yData = new ArrayList<Double>();
		for (int i = 0; i < daydealList.size(); i++) {
			double VOL5 = 0;
			for (int j = 0; j < TURNOVERDAY; j++) {
				if (i - j < 0) {
					break;
				}
				VOL5 += daydealList.get(i - j).getVOL();
			}
			yData.add(VOL5);

		}
		double max = 0;
		double min = 10000;
		for (int i = 0; i < yData.size(); i++) {
			Double VOL = yData.get(i);
			if (VOL.compareTo(max) > 0) {
				max = VOL;
			}
			if (VOL.compareTo(min) < 0) {
				min = VOL;
			}
		}
		// 设置比例
		for (int i = 0; i < yData.size(); i++) {
			yData.set(i, yData.get(i) * (maxY - minY) / max + minY);
		}

	}

}
